//
//  MappingExampleViewController.m
//  MappingExample
//

#import "MappingExampleViewController.h"

@implementation MappingExampleViewController

- (void)createRoute {
	
	int pointCount = 5;
	CLLocationCoordinate2D routeCoords[5];
	
	routeCoords[0] = CLLocationCoordinate2DMake(37.331689, -122.03071);
	routeCoords[1] = CLLocationCoordinate2DMake(37.331689, -122.03221);
	routeCoords[2] = CLLocationCoordinate2DMake(37.330259, -122.03221);
	routeCoords[3] = CLLocationCoordinate2DMake(37.330259, -122.03171);
	routeCoords[4] = CLLocationCoordinate2DMake(37.330519, -122.03055);
	
	MKPolyline *routeLine = [MKPolyline polylineWithCoordinates:routeCoords count:pointCount];
	[map addOverlay:routeLine];
	[routeLine release];
}
					 
- (void)viewDidLoad {
    [super viewDidLoad];
	
	map = [[MKMapView alloc] initWithFrame:[self.view bounds]];
	map.mapType = MKMapTypeSatellite;
	map.showsUserLocation = YES;
	
	CLLocationCoordinate2D coords = CLLocationCoordinate2DMake(37.331689,-122.03071);
	
	float zoomLevel = 0.002;
	MKCoordinateRegion region = MKCoordinateRegionMake(coords,
													   MKCoordinateSpanMake(zoomLevel, zoomLevel));
	
	[map setRegion:[map regionThatFits:region] animated:YES];
	
	[self.view addSubview:map];
	
	map.delegate = self;
	[self createRoute];
}

- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id <MKOverlay>)overlay {
	MKPolylineView *plView = [[MKPolylineView alloc] initWithOverlay:overlay];
	plView.strokeColor = [UIColor redColor];
	plView.lineWidth = 5.0;
	
	return [plView autorelease];
}

- (void)dealloc {
	[map release];
    [super dealloc];
}

@end
